package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

import static com.sky.enumeration.OperationType.INSERT;

@Mapper
public interface UserMapper {

    /**
     * 微信小程序后台登录
     *
     * @param openId
     * @return
     */
    @Select("select * from user where openid = #{openId}")
    User queryByOpenid(String openId);

    /**
     * 保存c端用户
     *
     * @param user
     */
    @AutoFill(INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user (openid, name, phone, sex, id_number, avatar, create_time) values " +
            "(#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")
    void save(User user);

    /**
     * 订单支付
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User getById(Long userId);

    /**
     * 用户数据统计
     * @param params
     * @return
     */
    Integer countUserByParams(Map params);

    /**
     * 用户数据统计
     * @param params
     * @return
     */
    List<Map> groupCountUserByParams(Map params);
}
